package com.ilink.groundservice.mapper.langflowApp;


import com.ilink.groundservice.entity.PO.langflowApp.Download;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface DownloadMapper {

    @Insert("INSERT INTO tb_download (user_id, flow_id) VALUES (#{userId}, #{flowId})")
    public void insert(Download download);

    @Delete("DELETE FROM tb_download WHERE user_id = #{userId} AND flow_id = #{flowId}")
    public void deleteDownloadsByUserId(String userId);

    @Delete("DELETE FROM tb_download WHERE flow_id = #{flowId}")
    public void deleteDownloadsByFlowId(String flowId);

    @Delete("DELETE FROM tb_download WHERE user_id = #{userId} AND flow_id = #{flowId}")
    public void delete(Download download);

    @Select("SELECT * FROM tb_download WHERE user_id = #{userId}")
    public List<Download> getDownloadsByUserId(String userId);

    @Select("SELECT * FROM tb_download WHERE flow_id = #{flowId}")
    public List<Download> getDownloadsByFlowId(String flowId);

    @Select("SELECT count(*) FROM tb_download WHERE user_id = #{userId} AND flow_id = #{flowId}")
    public Boolean exist(Download download);

    @Select("SELECT count(*) FROM tb_download WHERE flow_id = #{flowId}")
    public Integer getDownloadsCountByFlowId(String flowId);

    @Select("SELECT count(*) FROM tb_download WHERE user_id = #{userId}")
    public Integer getDownloadsCountByUserId(String userId);



}
